package pl.edu.agh.soa.monitoring;

import pl.edu.agh.soa.monitoring.cep.EventInfo;

import com.espertech.esper.client.EPServiceProvider;
import com.espertech.esper.client.EPStatement;
import com.espertech.esper.client.StatementAwareUpdateListener;
import com.espertech.esper.event.EventBean;

public class CallbackUpdateListener implements StatementAwareUpdateListener{
	
	public void update(EventBean[] newEvents, EventBean[] oldEvents,EPStatement stmt,
			EPServiceProvider epServiceProvider) {
		System.out.println("Need to insert into esper");
		EventInfo newEventsInfo = new EventInfo();
		newEventsInfo.setEvents(newEvents);
		newEventsInfo.setEventType(stmt.getEventType().getUnderlyingType().getName());
		//TODO tutaj mozna sprawdzic jeszcze co zwraca getName()
		newEventsInfo.setStatementID(stmt.getText());
		epServiceProvider.getEPRuntime().sendEvent(newEventsInfo);
	}

}
